
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>新建考核任务管理</title>
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/css/base/base.css?20201106.1">
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/js/common/language.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/layer/layer.js?20201106"></script>
    <%--<script src="../js/jquery/jquery.cookie.js"></script>--%>
    <script src="/lib/jquery.form.min.js"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <style>

        input{
            float: none;
        }
        .editAndDelete3{
            color: red;
        }
        .bar {
            height: 18px;
            background: green;
        }
        select{
            width: 228px !important;
            padding-left: 10px;
        }
        .newClass{
            float: right;
            width: 90px;
            height: 28px;
            background: url(../../img/file/cabinet01.png) no-repeat;
            color: #fff;
            font-size: 14px;
            line-height: 28px;
            margin: 2% 2% 0 0;
            cursor: pointer;
        }
        .del{
            color: red;
        }

    </style>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>

    <script>

    </script>
</head>
<body>
<div class="navigation">
    <img src="/img/commonTheme/${sessionScope.InterfaceModel}/newsManages2_1.png" alt="">
    <h2 class="head_title">新建考核任务管理</h2>
    <div class="newClass" id="newClass">
            <span style="margin-left: 30px;">
                <%--<img style="margin-right: 4px;margin-left: -11px;margin-bottom: 2px;" src="../../img/mywork/newbuildworjk.png" alt="">--%>
                返回
            </span>
    </div>
</div>
<div id="pagediv" class="tableMain">
    <%--<form id="ajaxform" action="/Hr/Incentive/addHrIncentive">--%>
        <table>
            <tbody>
            <tr>
                <td class="blue_text" width="20%">
                    <span style="color: red;">*</span>考核任务标题：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" name="incentiveAmount" id="budgetItemNo">
                </td>
            </tr>
            <%--<tr>--%>
                <%--<td class="blue_text" width="20%">--%>
                    <%--<p >考核人：</p>--%>
                <%--</td>--%>
                <%--<td width="80%" style="text-align: left">--%>
                    <%--<span><input disabled type="text" id="department"></span>--%>
                    <%--<a href="javascript:;" ><span class="btn adddept">添加</span></a>--%>
                    <%--<a href="javascript:;"><span class="btn clear del" >清除</span></a>--%>
                <%--</td>--%>
            <%--</tr>--%>
            <tr>
                <td class="blue_text" width="20%">
                    <p><span style="color: red;">*</span>被考核人：</p>
                </td>
                <td width="80%" style="text-align: left">
                    <input disabled class="td_title1 release1" id="itemExecuter" type="text">
                    <a href="javascript:;" class=" ml8 userPrivAdd btn add4" name="orgAdd">添加</a>
                   <a href="javascript:;" class=" ml8 userPrivClear btn clear4 del" name="orgClear">清除</a>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    <p><span style="color: red;">*</span>考核任务查看者：</p>
                </td>
                <td width="80%" style="text-align: left">
                    <input disabled class="td_title1 release1" id="itemManager" type="text" username="">
                     <a href="javascript:;" class=" ml8 userPrivAdd btn add3" name="orgAdd">添加</a>
                    <a href="javascript:;" class=" ml8 userPrivClear btn clear3 del" name="orgClear">清除</a>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    <span style="color: red;">*</span>考核单位：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" name="assessmentUnit" id="assessmentUnit" disabled>
                    <a href="javascipt:;" class="choose_dept" did="assessmentUnit">选择</a>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%"><span style="color: red;">*</span>考核试卷：</td>
                <td width="80%" style="text-align: left">
                    <select name="postPriv" class="BigSelect" id="newpriveItem">
                        <option value="0">请选择</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    <span style="color: red;">*</span>考核周期：
                </td>
                <td width="80%" style="text-align: left">
                    <select name="assessmentCycle"  id="assessmentCycle">
                    </select>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    <span style="color: red;">*</span>有效期：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" id="newbudgetItemBegintime" name="incentiveTime" readonly="readonly" onclick="laydate({format: 'YYYY-MM-DD'})">
                    至
                    <input style="width: 228px" type="text" id="newbudgetItemEndtime" name="incentiveTime" readonly="readonly" onclick="laydate({format: 'YYYY-MM-DD'})">
                </td>

            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    <fmt:message code="notice.th.reminder"/>：
                </td>
                <td width="80%" style="text-align: left" id="thing">
                    <input type="checkbox" class="remind" checked value="0">
                    <span><fmt:message code="notice.th.remindermessage"/></span>
                    <%--<input type="hidden" name="howRenind" >&nbsp;--%>
                    <input type="checkbox" class="smsRemind" value="1">
                    <span><fmt:message code="vote.th.UseRemind"/></span>
                    <%--<input type="hidden" name="smsDefault" value="1">--%>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    是否允许自评：
                </td>
                <td width="80%" style="text-align: left" >
                    <input type="radio" name="isSelfAssessment" checked value="1" >
                    <span>是</span>
                    <input type="radio" name="isSelfAssessment" value="0">
                    <span>否</span>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="padding: 5px;">
                    描述：
                    <div id="word_container" name="incentiveDescription">

                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center" class="btnarr">
                    <a href="javascript:;" class="savebtn"><fmt:message code="global.lang.save"/></a>
                </td>
            </tr>
            </tbody>
        </table>
    <%--</form>--%>
</div>
<script>
    /*默认【考核任务查看者】为当前登录人*/
    $.post('/users/getUserTheme',{_:new Date().getTime()},function (res) {
        $('#itemManager').val(res.object.userName)
        $('#itemManager').attr('user_id',res.object.userId)
    })
    
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    $.ajax({
        type:'get',
        url:'/ScoreGroupLeader/selScoreGroup',
        dataType:'json',
        data:{
            typeId:0,
        },
        success:function(res){
            var str='';
            if(res){
                $.each(res.obj,function(index,item){
                    str+='<option value="'+item.groupId+'">'+item.groupName+'</option>'
                });
                $('#newpriveItem').html(str);
                assessmentCycle($('#newpriveItem option:selected').text().substring(0,4))
            }
        }
    });
    /*切换考核试卷时*/
    $('#newpriveItem').change(function () {
        assessmentCycle($(this).children('option:selected').text().substring(0,4))
    })
    //验证
    function mustWrite() {
        if ($('#budgetItemNo').val() == "") {
            $.layerMsg({content: '考核任务标题！', icon: 2});
            return false;
        }
        if ($('#newpriveItem').val() == "") {
            $.layerMsg({content: '请选择考核试卷！', icon: 2});
            return false;
        }
        // if ($('#department').val() == "") {
        //     $.layerMsg({content: '请选择考核人！', icon: 2});
        //     return false;
        // }
        if ($('#itemManager').val() == "") {
            $.layerMsg({content: '请选择考核任务查看者！', icon: 2});
            return false;
        }
        if ($('#itemExecuter').val() == "") {
            $.layerMsg({content: '请选择被考核人！', icon: 2});
            return false;
        }
    
        if (!$('#assessmentUnit').attr('deptid')) {
            $.layerMsg({content: '请选择考核单位！', icon: 2});
            return false;
        }
        
        if ($('#assessmentCycle').val() == "") {
            $.layerMsg({content: '请选择考核周期！', icon: 2});
            return false;
        }
        
        if ($('#newbudgetItemBegintime').val() == "") {
            $.layerMsg({content: '请选择有效期开始时间！', icon: 2});
            return false;
        }
        
        if ($('#newbudgetItemEndtime').val() == "") {
            $.layerMsg({content: '请选择有效期结束时间！', icon: 2});
            return false;
        }
    }
    function inputcheck(name,value) {
        $('#'+name+'').val(value)
    }
    //截取字符串
    function getRequest() {
        var url = window.location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {

                theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);

            }
        }
        return theRequest;
    }
    var flowId= getRequest().flowId;
    var type= getRequest().type;
    // 查询提醒权限
    $.ajax({
        type:'get',
        url:'/smsRemind/getRemindFlag',
        dataType:'json',
        data:{
            type:15
        },
        success:function (res) {
            if(res.flag){
                if(res.obj.length>0){
                    var data = res.obj[0];
                    // 是否默认发送
                    if(data.isRemind=='0'){
                        $('.remind').prop("checked", false);
                    }else if(data.isRemind=='1'){
                        $('.remind').prop("checked", true);
                    }
                    // 是否手机短信默认提醒
                    if(data.isIphone=='0'){
                        $('.smsRemind').prop("checked", false);
                    } else if (data.isIphone=='1'){
                        $('.smsRemind').prop("checked", true);
                    }
                    // 是否允许发送事务提醒
                    if(data.isCan=='0'){
                        $('.remind').prop("checked", false);
                        $('.smsRemind').prop("checked", false);
                        $('#thing').parent('tr').hide();
                    }

                }
            }
        }
    })
    // 编辑
    if(type==0){
        $.ajax({
            type: 'post',
            url: '/ScoreFlowLeader/selScoreFlow',
            dataType: 'json',
            data: {
                flowId:flowId
            },
            success: function (res) {
                var objs=  res.obj[0]
                $.ajax({
                    type:'get',
                    url:'/ScoreGroupLeader/selScoreGroup',
                    dataType:'json',
                    data:{
                        typeId:0,
                    },
                    success:function(res){
                        var str='';
                        if(res){
                            $.each(res.obj,function(index,item){
                                str+='<option value="'+item.groupId+'">'+item.groupName+'</option>'
                            });
                            $('#newpriveItem').html(str);
                            $('select[name="postPriv"] ').find("option[value='" + objs.groupId + "']").attr("selected",true);
                            assessmentCycle($('#newpriveItem option:selected').text().substring(0,4),function () {
                                $('#assessmentCycle').val(objs.assessmentCycle)
                            })
                        }
                    }
                });
                inputcheck('budgetItemNo',objs.flowTitle)
                // inputcheck('department',objs.rankmanName)
                inputcheck('itemExecuter',objs.participantName)
                $('#itemExecuter').attr('username',objs.participantName)
                $('#itemExecuter').attr('user_id',objs.participant)
                
                $('#assessmentUnit').val(objs.assessmentUnitName || '');
                $('#assessmentUnit').attr('deptId', objs.assessmentUnit || '');

                inputcheck('itemManager',objs.viewUserName)
                $('#itemManager').attr('username',objs.viewUserName)
                $('#itemManager').attr('user_id',objs.viewUserId)

                // inputcheck('newpriveItem',objs.groupId)
                inputcheck('newbudgetItemBegintime',objs.beginDateStr)
                inputcheck('newbudgetItemEndtime',objs.endDateStr)
                $('input[name=isSelfAssessment][value='+objs.isSelfAssessment+']').prop("checked", "checked");
                if(objs.remind=='0'){
                    $('.remind').prop("checked", false);
                }else if(objs.remind=='1'){
                    $('.remind').prop("checked", true);
                }
                if(objs.smsRemind=='0'){
                    $('.smsRemind').prop("checked", false);
                } else if (objs.smsRemind=='1'){
                    $('.smsRemind').prop("checked", true);
                }
                ue.ready(function(){
                    ue.setContent(objs.flowDesc);
                });
                $('.head_title').html("修改考核任务管理");
            }
        })
        $('.savebtn').click(function () {
            if (mustWrite() == false) {
                return;
            }
            var html = ue.getContent();
            var budgetItemNo = $('#budgetItemNo').val();
            /*var department = $('#department').val().slice(0,$('#department').val().length-1);*/
            var itemExecuter = $('#itemExecuter').attr("user_id");
            // var user = $('#rescueUser').attr('username')
            // var department = $('#department').attr("user_id");
            var itemManager = $('#itemManager').attr("user_id");
            /*console.log(itemExecuter);*/
            // var itemExecuter = $('#itemExecuter').val().slice(0,$('#itemExecuter').val().length-1);
            /* var itemManager = $('#itemManager').val().slice(0,$('#itemManager').val().length-1);*/
            var priveItem = $('#newpriveItem option:selected').val();
            var budgetItemBegintime = $('#newbudgetItemBegintime').val();
            var budgetItemEndtime = $('#newbudgetItemEndtime').val();
            var isSelfAssessment = $('input[name=isSelfAssessment]:checked').val();
            var assessmentUnit =  $('#assessmentUnit').attr('deptId').replace(/,$/, '');
            var assessmentCycle = $('#assessmentCycle').val();
            
            $.ajax({
                url: '/ScoreFlowLeader/modifyScoreFlow',
                type: 'post',
                data: {
                    flowId:flowId,
                    flowTitle: budgetItemNo,
                    // rankman: department,
                    participant: itemExecuter,
                    viewUserId: itemManager,
                    groupId: priveItem,
                    beginDate:budgetItemBegintime,
                    endDate:budgetItemEndtime,
                    beginDateStr: budgetItemBegintime,
                    endDateStr: budgetItemEndtime,
                    flowDesc: html,
                    isSelfAssessment:isSelfAssessment,
                    remind:function(){
                        if($('.remind').prop('checked')==false){
                            return '0';
                        }else {
                            return '1';
                        }
                    },
                    smsRemind:function(){
                        if($('.smsRemind').prop('checked')==false){
                            return '0';
                        }else {
                            return '1';
                        }
                    },
                    assessmentUnit:assessmentUnit,
                    assessmentCycle:assessmentCycle,
                },
                dataType: 'json',
                success: function (res) {
                    if (res.msg == "新建项目重复") {
                        layer.msg("新建项目重复", {
                            icon: 2,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        });
                    } else {
                        layer.msg("修改成功", {
                            icon: 1,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            location.href = "/ScoreFlowLeader/assessmentTaskment"
                        });
                    }
                }
            })
        })
    }else{//新建
        /*考核单位显示*/
        $.post('/InstitutionSort/getDeptType', {_: new Date().getTime()}, function (res) {
            $('#assessmentUnit').val(res.object.deptName)
            $('#assessmentUnit').attr('deptId', res.object.deptId)
        });
        //点击保存
        $('.savebtn').click(function () {
            if (mustWrite() == false) {
                return;
            }
            var html = ue.getContent();
         //   console.log(html)

            var budgetItemNo = $('#budgetItemNo').val();
            /*var department = $('#department').val().slice(0,$('#department').val().length-1);*/
            var itemExecuter = $('#itemExecuter').attr("user_id");
            // var department = $('#department').attr("user_id");
            var itemManager = $('#itemManager').attr("user_id");
            /*console.log(itemExecuter);*/
            // var itemExecuter = $('#itemExecuter').val().slice(0,$('#itemExecuter').val().length-1);
            /* var itemManager = $('#itemManager').val().slice(0,$('#itemManager').val().length-1);*/
            var priveItem = $('#newpriveItem option:selected').val();
            var budgetItemBegintime = $('#newbudgetItemBegintime').val();
            var budgetItemEndtime = $('#newbudgetItemEndtime').val();
            var isSelfAssessment = $('input[name=isSelfAssessment]:checked').val();
            var itemDesc = $('#itemDesc').val();
            var assessmentUnit =  $('#assessmentUnit').attr('deptId').replace(/,$/, '');
            var assessmentCycle = $('#assessmentCycle').val();
            $.ajax({
                url: '/ScoreFlowLeader/addScoreFlow',
                type: 'post',
                data: {
                    flowTitle: budgetItemNo,
                    // rankman: department,
                    participant: itemExecuter,
                    viewUserId: itemManager,
                    groupId: priveItem,
                    beginDate:budgetItemBegintime,
                    endDate:budgetItemEndtime,
                    beginDateStr: budgetItemBegintime,
                    endDateStr: budgetItemEndtime,
                    flowDesc: html,
                    isSelfAssessment:isSelfAssessment,
                    remind:function(){
                        if($('.remind').prop('checked')==false){
                            return '0';
                        }else {
                            return '1';
                        }
                    },
                    smsRemind:function(){
                        if($('.smsRemind').prop('checked')==false){
                            return '0';
                        }else {
                            return '1';
                        }
                    },
                    assessmentUnit:assessmentUnit,
                    assessmentCycle:assessmentCycle
                },
                dataType: 'json',
                success: function (res) {
                    if (res.msg == "新建项目重复") {
                        layer.msg("新建项目重复", {
                            icon: 2,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        });
                    } else {
                        layer.msg("新建成功", {
                            icon: 1,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            location.href = "/ScoreFlowLeader/assessmentTaskment"
                        });
                    }
                }
            })
        })
    }
    
    // 选择部门
    $('.choose_dept').on('click', function(){
        dept_id = $(this).attr('did');
        $.popWindow('/common/selectDept?0');
    });

    //下拉列表

    //添加人员
    // $('.adddept').click(function(){
    //     user_id='department';
    //     /*$.popWindow("../../common/roleMapper");*/
    //     $.popWindow("../../common/selectUser");
    // })
    $('.add3').click(function(){
        user_id='itemManager';
        $.popWindow("../../common/selectUser");
    })
    $('.add4').click(function(){
        user_id='itemExecuter';
        $.popWindow("../../common/selectUser");
    })
    $('.clear').click(function(){
        $(this).siblings().find('input').removeAttr('deptname').removeAttr('deptno').removeAttr('deptid').removeAttr('user_id').val('')
    })
    // 清空人员信息
    $('.clear3').click(function () {
        $('#itemManager').attr("privid", "");
        $('#itemManager').attr("userpriv", "");
        $('#itemManager').attr("user_id", "");
        $('#itemManager').val("");
    });
    // $('.clear').click(function () {
    //     $('#department').attr("privid", "");
    //     $('#department').attr("userpriv", "");
    //     $('#department').attr("user_id", "");
    //     $('#department').val("");
    // });
    $('.clear4').click(function () {
        $('#itemExecuter').attr("privid", "");
        $('#itemExecuter').attr("userpriv", "");
        $('#itemExecuter').attr("user_id", "");
        $('#itemExecuter').val("");
    });
    var user_id='';
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    UEimgfuc();

$(function () {
    $('input[name="salaryMonth"]').val(queryTime());

    fileuploadFn('#uploadinputimg', $('#files_txt'));

//    返回
    $(document).on('click', '.newClass', function () {
        $(window.parent.document).find('.main').find('iframe').prop('src', '/ScoreFlowLeader/assessmentTaskment')
    })





    //删除附件
    function deleteChatment(data, element) {

        layer.confirm('<fmt:message code="workflow.th.que" />？', {
            btn: ['<fmt:message code="global.lang.ok" />', '<fmt:message code="depatement.th.quxiao" />'], //按钮
            title: "<fmt:message code="notice.th.DeleteAttachment" />"
        }, function () {
            //确定删除，调接口
            $.ajax({
                type: 'get',
                url: '/delete',
                dataType: 'json',
                data: data,
                success: function (res) {

                    if (res.flag == true) {
                        layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
                        element.remove();
                    } else {
                        layer.msg('<fmt:message code="lang.th.deleSucess" />', {icon: 6});
                    }
                }
            });

        }, function () {
            layer.closeAll();
        });
    }

    function queryTime() {
        function p(s) {
            return s < 10 ? '0' + s : s;
        }

        var myDate = new Date();
        //获取当前年
        var year = myDate.getFullYear();
        //获取当前月
        var month = myDate.getMonth() + 1;
        //获取当前日
        var date = myDate.getDate();
        var h = myDate.getHours();       //获取当前小时数(0-23)
        var m = myDate.getMinutes();     //获取当前分钟数(0-59)
        var s = myDate.getSeconds();
//        var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);
        var now = year + '-' + p(month);
//        if(type==undefined){
//            return now;
//        }else {
//            return year+'-'+p(month)+"-"+p(date)
//        }
        return now;


    }

    // 用正则表达式获取地址栏参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if (r != null) {
            return unescape(r[2]);
        } else {
            return null;
        }
    }
})

    /*考核周期显示*/
    function assessmentCycle(type,fn) {
        $.get('/ScoreFlowLeader/selectCycle',{type:type},function (res) {
            if(res.flag){
                var str='<option value="">请选择</option>';
                $.each(res.obj,function(index,item){
                    str+='<option value="'+item.codeName+'">'+item.codeName+'</option>'
                });
                $('#assessmentCycle').html(str);
                if(fn){
                    fn()
                }
            }
        })
    }
</script>
</body>
</html>